package cn.yunhe.controller;

import cn.yunhe.entity.Admin;
import cn.yunhe.entity.Stock;
import cn.yunhe.entity.Type;
import cn.yunhe.service.IAdminService;
import cn.yunhe.service.IStockService;
import cn.yunhe.service.ITypeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 邓永凯
 * 根据id查询出仓库信息
 */
@WebServlet("/after/SearchStockByIdServlet")
public class SearchStockById extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取前台传过来的值并转为int型
        int stockId = Integer.parseInt(request.getParameter("stockId"));
        //获取指定id的仓库信息
        IStockService iStockService = new IStockService();
        Stock stock = iStockService.getStockById(stockId);
        //获取全部的类别信息
        ITypeService iTypeService = new ITypeService();
        List<Type> typeList = iTypeService.getAllType();
       //获取全部的管理员信息
        IAdminService iAdminService = new IAdminService();
        List<Admin> adminList = iAdminService.getAllAdmin();
        //保存到request域里面
        request.setAttribute("stock",stock);
        request.setAttribute("typeList",typeList);
        request.setAttribute("adminList",adminList);
        //转发
        request.getRequestDispatcher("stock-update.jsp").forward(request,response);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
